package thinker.miracle.ams.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import thinker.miracle.ams.dao.ResultDao;
import thinker.miracle.ams.entity.ResultEntity;
import thinker.miracle.ams.model.ResultModel;
import thinker.miracle.utils.BeanUtil;


/**
 * @author bo.chen
 *
 */
@Service
public class ResultService {
	
	@Autowired
	ResultDao resultDao;

	/**
	 * 保存
	 * 
	 * @param paramsEntity
	 *
	 */
	@Transactional
	public void save(ResultEntity resultEntity){
		if(resultEntity != null && resultEntity.getId() == 0){
			resultDao.insert(resultEntity);
		}else if(resultEntity != null && resultEntity.getId() > 0){
			resultDao.updateSelective(resultEntity);
		}else if(resultEntity == null)
			throw new RuntimeException("null piont exception");
	}
	
	/**
	 * <p> 获取 参数</p>
	 * 
	 * @param interfaceId
	 * @return
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * 
	 */
	public List<ResultModel> getByInterfaceId(int interfaceId) throws InstantiationException, IllegalAccessException{
		List<ResultEntity> resultEntitys = resultDao.findByInterfaceId(interfaceId);
		return BeanUtil.copyPropertiesList(resultEntitys, ResultModel.class);
	}
}